Set up

options(warn = -1) 
options(readr.show_types = FALSE)

suppressMessages({
library(tidyverse)
library(dplyr)
library(stringr)
library(data.table)
library(mapview)
library(sf)
library(gt)
library(leaflet)
})

Gathering and Organizing PLUTO Data

url <- "https://tonyfraser-data.s3.amazonaws.com/nyc-addresses/nyc_pluto_23v3_csv/pluto_23v3.csv"
pluto_path <- "./nogit_cache/_pluto_23v3.csv"
if (!file.exists(pluto_path)) {
    download.file(url, pluto_path, mode = "wb")
}
pluto <- read_csv(pluto_path)
dfbrklyn <- filter(pluto, borocode == "3", pfirm15_flag == "1")
dfqueens <- filter(pluto, borocode == "4", pfirm15_flag == "1")
dfbronx <- filter(pluto, borocode == "2", pfirm15_flag == "1")
dfmanhattan <- filter(pluto, borocode == "1", pfirm15_flag ==
    "1")
dfstaten <- filter(pluto, borocode == "5", pfirm15_flag == "1")

# df_sample_Brooklyn<-dfbrklyn df_sample_Queens<-dfqueens
# df_sample_Bronx<-dfbronx df_sample_manhattan<-dfmanhattan
# df_sample_staten<-dfstaten
df_sample_Brooklyn <- sample_n(dfbrklyn, 2192)
df_sample_Queens <- sample_n(dfqueens, 2155)
df_sample_Bronx <- sample_n(dfbronx, 1399)
df_sample_manhattan <- sample_n(dfmanhattan, 1283)
df_sample_staten <- sample_n(dfstaten, 2040)

Gathering and Organizing PLUTO Data for Popup

df_sample_Brooklyn_flood <- df_sample_Brooklyn %>%
    mutate(Brooklyn_Data = paste("Building Area: ", bldgarea,
        "<br/>Lot Area: ", lotarea, "<br/>Total Number of Units: ",
        unitstotal, "<br/>Number of Buildings: ", numbldgs, "<br/>Number of Floors: ",
        numfloors, "<br/>Assessed Total: ", assesstot, "<br/>Year Built: ",
        yearbuilt, "<br/>Location: ", address)) %>%
    mutate(County = paste("Kings County"))

df_sample_Queens_flood <- df_sample_Queens %>%
    mutate(Queens_Data = paste("Building Area: ", bldgarea, "<br/>Lot Area: ",
        lotarea, "<br/>Total Number of Units: ", unitstotal,
        "<br/>Number of Buildings: ", numbldgs, "<br/>Number of Floors: ",
        numfloors, "<br/>Assessed Total: ", assesstot, "<br/>Year Built: ",
        yearbuilt, "<br/>Location: ", address)) %>%
    mutate(County = paste("Queens County"))

df_sample_Bronx_flood <- df_sample_Bronx %>%
    mutate(Bronx_Data = paste("Building Area: ", bldgarea, "<br/>Lot Area: ",
        lotarea, "<br/>Total Number of Units: ", unitstotal,
        "<br/>Number of Buildings: ", numbldgs, "<br/>Number of Floors: ",
        numfloors, "<br/>Assessed Total: ", assesstot, "<br/>Year Built: ",
        yearbuilt, "<br/>Location: ", address)) %>%
    mutate(County = paste("Bronx County"))

df_sample_manhattan_flood <- df_sample_manhattan %>%
    mutate(Manhattan_Data = paste("Building Area: ", bldgarea,
        "<br/>Lot Area: ", lotarea, "<br/>Total Number of Units: ",
        unitstotal, "<br/>Number of Buildings: ", numbldgs, "<br/>Number of Floors: ",
        numfloors, "<br/>Assessed Total: ", assesstot, "<br/>Year Built: ",
        yearbuilt, "<br/>Location: ", address)) %>%
    mutate(County = paste("New York County"))

df_sample_staten_flood <- df_sample_staten %>%
    mutate(Staten_Island_Data = paste("Building Area: ", bldgarea,
        "<br/>Lot Area: ", lotarea, "<br/>Total Number of Units: ",
        unitstotal, "<br/>Number of Buildings: ", numbldgs, "<br/>Number of Floors: ",
        numfloors, "<br/>Assessed Total: ", assesstot, "<br/>Year Built: ",
        yearbuilt, "<br/>Location: ", address)) %>%
    mutate(County = paste("Richmond County"))

Creating Map Data

m_df_sample_staten_flood<-mapview(df_sample_staten_flood,crs = 4269,  xcol = "longitude", ycol = "latitude",zcol="County", legend = TRUE, popup="Staten_Island_Data", grid = FALSE, layer.name = "Richmond County", col.regions = "red" )

m_df_sample_manhattan_flood<-mapview(df_sample_manhattan_flood,crs = 4269,  xcol = "longitude", ycol = "latitude", zcol="County",popup="Manhattan_Data",legend = TRUE,  grid = FALSE,layer.name = "New York County", col.regions = "green" )

m_df_sample_Bronx_flood<-mapview(df_sample_Bronx_flood,crs = 4269,  xcol = "longitude", ycol = "latitude",zcol="County", legend = TRUE, popup="Bronx_Data",grid = FALSE,layer.name = "Bronx County", col.regions = "blue" )

m_df_sample_Queens_flood<-mapview(df_sample_Queens_flood,crs = 4269,  xcol = "longitude", ycol = "latitude",zcol="County", legend = TRUE, popup="Queens_Data",grid = FALSE , layer.name = "Queens County", col.regions = "orange" )

m_df_sample_Brooklyn_flood<-mapview(df_sample_Brooklyn_flood,crs = 4269,  xcol = "longitude", ycol = "latitude",zcol="County", legend = TRUE, popup="Brooklyn_Data", grid = FALSE,layer.name = "Kings County", col.regions = "black")

Statistical Sample of Map of Flood Zone Addresses

m_df_sample_Brooklyn_flood+m_df_sample_Queens_flood+m_df_sample_Bronx_flood+m_df_sample_manhattan_flood+m_df_sample_staten_flood

```